home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- TestNotify.c
- ©LFSoft 1995
-
- This code is fully a dommain public: Use it as you want...
-
- Test notifications from registery.library, and shared port mecanisme.
-
- 24/07/1995 First version.
-
- /!\ Must be started from a CLI or a SHELL because of use of some stdio
- output...
-
- Notes:
- * All libraries (but registery.library) are openned and closed
- automaticaly by DICE's autoinit feature. You must add some code for
- others compilers.
- * Note that we use the same class id for normal notification and for
- NWF (with a different code), but you may use different ones...
-
- Testing:
- ~~~~~~~~
- + Start 2 shells.
-
- + Run TestNotify from the first:
- Shell #7 STAT-RAM: > TestNotify
-
- + Test gadget's messages by clicking ... on the gadget !
-
- + Run TestResouce from the 2nd shell to test others messages:
- Shell #5 STAT-RAM: > TestResource -n TST_RESOURCE
- This send a normal notification.
- "*TST Notif* Resource notification : Code 0" should be
- displayed in the first shell.
-
- Shell #5 STAT-RAM: >TestResource -l TST_RESOURCE
- This lock the resource.
- When you unlock the resouce (CTRL-C), the following message
- is displayed by TestNotify:
- "*TST Notif* Resource notification : Code 1"
-
- + Close all
-
- ***********************************************************************/
-
- #include <intuition/intuition.h>
- #include <proto/intuition.h>
- #include <proto/exec.h>
- #include <proto/registry.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- /*
- * Globals variables
- */
- struct Library *RegistryBase=NULL;
- struct Window *win1=NULL;
-
- // Note : We must initialise globales variables for cleanup() function
- ULONG nclass=0; // Notification class
- APTR resource=NULL;
- APTR notif=NULL;
- APTR notifwf=NULL; // Notify when free
-
- /*
- * Window's definitions
- * (in old 1.3 style, but it still work under newer OS, tanks Amiga).
- */
-
- SHORT Border1_Vectors1[] = {
- 0,0,
- 138,0,
- 138,14,
- 0,14,
- 0,0
- };
- struct Border Border1_1 = {
- -2,-1, /* XY origin relative to container TopLeft */
- 3,0,JAM1, /* front pen, back pen and drawmode */
- 5, /* number of XY vectors */
- Border1_Vectors1, /* pointer to XY vectors */
- NULL /* next border in list */
- };
-
- struct IntuiText IText1_1 = {
- 3,0,JAM2, /* front and back text pens, drawmode and fill byte */
- 32,2, /* XY origin relative to container TopLeft */
- NULL, /* font pointer or NULL for default */
- "Gadget1", /* pointer to text */
- NULL /* next IntuiText structure */
- };
-
- struct Gadget gadw1_1 = {
- NULL, /* next gadget */
- 19,14, /* origin XY of hit box relative to window TopLeft */
- 135,13, /* hit box width and height */
- NULL, /* gadget flags */
- RELVERIFY, /* activation flags */
- BOOLGADGET, /* gadget type flags */
- (APTR)&Border1_1, /* gadget border or image to be rendered */
- NULL, /* alternate imagery for selection */
- &IText1_1, /* first IntuiText structure */
- NULL, /* gadget mutual-exclude long word */
- NULL, /* SpecialInfo structure */
- 1, /* user-definable data */
- NULL /* pointer to user-definable data */
- };
-
- struct NewWindow NewWindowStructure1 = {
- 70,32, /* window XY origin relative to TopLeft of screen */
- 189,34, /* window width and height */
- 0,1, /* detail and block pens */
- GADGETUP|CLOSEWINDOW, /* IDCMP flags */
- WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH|WINDOWCLOSE, /* other window flags */
- &gadw1_1, /* first gadget in gadget list */
- NULL, /* custom CHECKMARK imagery */
- "Notify example", /* window title */
- NULL, /* custom screen pointer */
- NULL, /* custom bitmap */
- 5,5, /* minimum width and height */
- 640,200, /* maximum width and height */
- WBENCHSCREEN /* destination screen type */
- };
-
- /*
- * Cleanup function
- *
- * Note: Free objects in the reverse order than allocated.
- *
- */
-
- void cleanup() {
- if(RegistryBase){
- RL_RemoveNotify(notif); // Free notifications requests
- RL_RemoveNotify(notifwf);
- RL_UnRegisterResource(resource); // Free our resource
- RL_UnRegisterClass(nclass); // Free our class
- CloseLibrary(RegistryBase); // and close the library
- }
- if(win1 !=NULL)CloseWindow(win1);
- }
-
- void main(void)
- {
- struct IntuiMessage *IM;
- atexit(cleanup);
-
- if((win1 = (struct Window *)
- OpenWindow(&NewWindowStructure1))==0)
- exit(20);
-
- /*************************************************************************
- All registry thing
- ************************************************************************/
- // Open the library
- if(!(RegistryBase = OpenLibrary("registry.library",0))){
- puts("Can't open registry.library");
- exit(20);
- }
-
- // Get an uniq Class id
- if(!(nclass=RL_RegisterClass("TST_RES_NOTIF"))){
- puts("Can't registring my class");
- exit(20);
- }
-
- // register our resource
- if(!(resource=RL_RegisterResource("TST_RESOURCE"))){
- puts("Can't register my resource");
- exit(20);
- }
-
- // Add a notification request
- if(!(notif=RL_AddNotify(resource,RL_TP_NOTIF,win1->UserPort,nclass,0))){
- puts("Can't add my notification request");
- exit(20);
- }
-
- // Add a notification request for free resource
- if(!(notifwf=RL_AddNotify(resource,RL_TP_NWF,win1->UserPort,nclass,1))){
- puts("Can't add my notification request (NWF)");
- exit(20);
- }
-
- RL_StartNotify(notif); // Enable notifications
- RL_StartNotify(notifwf);
-
- /*************************************************************************
- Standard messages loop
- ************************************************************************/
-
- while(win1){
- Wait(1L << win1->UserPort->mp_SigBit ); // Doesn't hurt multitaching
- while (IM = (struct IntuiMessage *) GetMsg(win1->UserPort)){
- switch(IM->Class){
- case CLOSEWINDOW :
- ReplyMsg((struct Message *)IM);
- puts("*TST Notif* window closed");
- if(win1 !=NULL){ CloseWindow(win1); win1=NULL; }
- break;
- case GADGETUP :
- puts("*TST Notif* Gadget clicked");
- ReplyMsg((struct Message *)IM);
- break;
- default:
- if(IM->Class == nclass){ // C compiler hate non-contant arg for case
- printf("*TST Notif* Resource notification : Code %d\n",IM->Code);
- }
- ReplyMsg((struct Message *)IM);
- break;
- }
- if(!win1) break;
- }
- }
- }
-